﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.Practices.ServiceLocation;
using System.Web.UI;
using QKen.SPA.Common.Utility;

namespace QKen.SPA.Portal
{
    public class BasePage:Page
    {
        #region 属性

        public new CrmUserPrincipal User
        {
            get { return base.User as CrmUserPrincipal; }
        }

        public string CurrentAppPath
        {
            get
            {
                string appPath = Request.RawUrl.ToLower();

                if (Request.ApplicationPath.ToLower() != "/")
                {
                    appPath = appPath.Replace(Request.ApplicationPath.ToLower(), "");
                }

                if (appPath.Contains("?"))
                {
                    appPath = appPath.Substring(0, appPath.IndexOf("?"));
                }
                //return appPath.TrimStart('/');
                return "~/" + appPath.TrimStart('/');
            }
        }

        #endregion

        protected T GetServiceInstance<T>()
        {
            //if (Convert.ToBoolean(ConfigHelper.ReadConfig("EnableWCF")))
            //{
            //    using (ServiceManager<T> sm = new ServiceManager<T>())
            //    {
            //        return sm.Service;
            //    }
            //}
            //else
            {
                T contract = ServiceLocator.Current.GetInstance<T>();
                return contract;
            }
        }
    }
}